#!/bin/sh
# Script de creación de máquina virtual sobre VirtualBox
NAME="ODNETWORK"

FS="`pwd`/storage.ext2.$NAME"
# Interfaz conectado a la red, un dhcp server debería estar presente
HOST_IF="eth1"
ISO_PATH="`pwd`/../opendomo-rel-486.iso"

VBoxManage createvm -name $NAME -ostype Linux26
VBoxManage registervm $HOME/.VirtualBox/Machines/$NAME/$NAME.xml

if test -f $FS; then
	echo "Using $FS"
else
	dd if=/dev/zero of=$FS count=999999 && mkfs.ext2 -F $FS || exit 1
	echo "Almacenaje creado!"		

	echo "Almacenaje de configuraciones"
	mkdir -p ./mnt
	sudo mount  $FS ./mnt -o loop

	sudo echo '
LABEL="odconf"
CONFDEVICE="1"
' > ./mnt/opendomo.cfg

	sudo umount $FS ./mnt
	rm -fr ./mnt
fi


if test -f ${FS}.vdi; then
	echo "Using $FS.vdi"
else
	VBoxManage convertdd ${FS} ${FS}.vdi || exit 1
fi

VBoxManage modifyvm $NAME --memory 64 --usb on || exit 1
VBoxManage modifyvm $NAME --dvd $ISO_PATH --hda $FS.vdi || exit 1
VBoxManage modifyvm $NAME -boot1 dvd -nic1 hostif -hostifdev1 $HOST_IF || exit 1


